package com.esri.core.geometry;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class VertexDescriptionHash {
    private static VertexDescription b;
    private static VertexDescription c;
    private static final VertexDescriptionHash d = new VertexDescriptionHash();
    Map<Integer, WeakReference<VertexDescription>> a = new HashMap();

    private VertexDescriptionHash() {
        add(new VertexDescriptionDesignerImpl());
        VertexDescriptionDesignerImpl vertexDescriptionDesignerImpl = new VertexDescriptionDesignerImpl();
        vertexDescriptionDesignerImpl.addAttribute(1);
        add(vertexDescriptionDesignerImpl);
    }

    public static VertexDescriptionHash getInstance() {
        return d;
    }

    public VertexDescription getVD2D() {
        return b;
    }

    public VertexDescription getVD3D() {
        return c;
    }

    public synchronized VertexDescription add(VertexDescriptionDesignerImpl vertexDescriptionDesignerImpl) {
        int hashCode = vertexDescriptionDesignerImpl.hashCode();
        VertexDescription vertexDescription = b;
        if (vertexDescription != null && vertexDescription.hashCode() == hashCode && vertexDescriptionDesignerImpl.isDesignerFor(b)) {
            return b;
        }
        VertexDescription vertexDescription2 = c;
        if (vertexDescription2 != null && vertexDescription2.hashCode() == hashCode && vertexDescriptionDesignerImpl.isDesignerFor(c)) {
            return c;
        }
        VertexDescription vertexDescription3 = null;
        if (this.a.containsKey(Integer.valueOf(hashCode)) && (vertexDescription3 = this.a.get(Integer.valueOf(hashCode)).get()) == null) {
            this.a.remove(Integer.valueOf(hashCode));
        }
        if (vertexDescription3 == null) {
            vertexDescription3 = vertexDescriptionDesignerImpl.f();
            if (vertexDescription3.getAttributeCount() == 1) {
                b = vertexDescription3;
            } else if (vertexDescription3.getAttributeCount() == 2 && vertexDescription3.getSemantics(1) == 1) {
                c = vertexDescription3;
            } else {
                this.a.put(Integer.valueOf(hashCode), new WeakReference<>(vertexDescription3));
            }
        }
        return vertexDescription3;
    }
}
